package com.cnap.model.schedule.engine;

import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.cnap.utils.JsonUtil;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 部署策略请求
 *
 * @author xc
 **/
public class DeployPolicyDistributeReq {
    // 集群信息
    @JsonProperty(value = "clusterNames")
    private List<String> clusters;
    // 部署配置
    private String deployPolicyConfig;
    // 路径
    private String path;
    // 扩缩容配置
    private List<String> scalePolicyConfigs;
    // 服务id
    private String svcId;
    // yaml
    private String yaml;
    // 应用分类
    private String appCategory;
    // 框架
    private String framework;
    // 场景标签
    @JsonProperty(value = "sceneTag")
    private List<String> sceneTags;
    // 技术标签
    @JsonProperty(value = "technologyTag")
    private List<String> technologyTags;

    private String userName;

    /**
     * get
     *
     * @return Clusters
     */
    public List<String> getClusters() {
        return clusters;
    }

    /**
     * set
     *
     * @param clusters clusters
     */
    public void setClusters(List<String> clusters) {
        this.clusters = clusters;
    }

    /**
     * get
     *
     * @return DeployPolicyConfig
     */
    public String getDeployPolicyConfig() {
        return deployPolicyConfig;
    }

    /**
     * set
     *
     * @param deployPolicyConfig deployPolicyConfig
     */
    public void setDeployPolicyConfig(String deployPolicyConfig) {
        this.deployPolicyConfig = deployPolicyConfig;
    }

    /**
     * get
     *
     * @return Path
     */
    public String getPath() {
        return path;
    }

    /**
     * set
     *
     * @param path path
     */
    public void setPath(String path) {
        this.path = path;
    }

    /**
     * get
     *
     * @return ScalePolicyConfigs
     */
    public List<String> getScalePolicyConfigs() {
        return scalePolicyConfigs;
    }

    /**
     * set
     *
     * @param scalePolicyConfigs scalePolicyConfigs
     */
    public void setScalePolicyConfigs(List<String> scalePolicyConfigs) {
        this.scalePolicyConfigs = scalePolicyConfigs;
    }

    /**
     * get
     *
     * @return SvcId
     */
    public String getSvcId() {
        return svcId;
    }

    /**
     * set
     *
     * @param svcId svcId
     */
    public void setSvcId(String svcId) {
        this.svcId = svcId;
    }

    /**
     * get
     *
     * @return Yaml
     */
    public String getYaml() {
        return yaml;
    }

    /**
     * set
     *
     * @param yaml yaml
     */
    public void setYaml(String yaml) {
        this.yaml = yaml;
    }

    /**
     * get
     *
     * @return AppCategory
     */
    public String getAppCategory() {
        return appCategory;
    }

    /**
     * set
     *
     * @param appCategory appCategory
     */
    public void setAppCategory(String appCategory) {
        this.appCategory = appCategory;
    }

    /**
     * get
     *
     * @return Framework
     */
    public String getFramework() {
        return framework;
    }

    /**
     * set
     *
     * @param framework framework
     */
    public void setFramework(String framework) {
        this.framework = framework;
    }

    /**
     * get
     *
     * @return SceneTags
     */
    public List<String> getSceneTags() {
        return sceneTags;
    }

    /**
     * set
     *
     * @param sceneTags sceneTags
     */
    public void setSceneTags(List<String> sceneTags) {
        this.sceneTags = sceneTags;
    }

    /**
     * get
     *
     * @return TechnologyTags
     */
    public List<String> getTechnologyTags() {
        return technologyTags;
    }

    /**
     * set
     *
     * @param technologyTags technologyTags
     */
    public void setTechnologyTags(List<String> technologyTags) {
        this.technologyTags = technologyTags;
    }

    /**
     * get
     *
     * @return UserName
     */
    public String getUserName() {
        return userName;
    }

    /**
     * set
     *
     * @param userName userName
     */
    public void setUserName(String userName) {
        this.userName = userName;
    }

    /**
     * 转换成json
     *
     * @return json
     */
    public String transToJson() {
        String str = JsonUtil.objectToJsonStr(this);
        if (CharSequenceUtil.isEmpty(str)) {
            return null;
        }
        JSONObject jsonObject = JSONUtil.parseObj(str);
        jsonObject.set("deployPolicyConfig", JSONUtil.parseObj(deployPolicyConfig));

        List<JSONObject> jsonObjects = scalePolicyConfigs.stream().map(JSONUtil::parseObj).collect(Collectors.toList());
        jsonObject.set("scalePolicyConfigs", JSONUtil.parse(jsonObjects));
        return jsonObject.toString();
    }

}
